package com.hsurosy.hsuchain.nft.api.chain.response;

import lombok.Data;

/**
 * 区块链处理响应类
 *
 * @Author Hsu琛君珩
 * @Date 2024-10-03 19:29
 * @Description
 * @Version: v1.0.0
 */
@Data
public class ChainProcessResponse<T> extends BaseResponse {

    private static final long serialVersionUID = 1L;

    /**
     * 链处理响应的构建器类
     */
    public static class Builder<T> {
        private T data;

        private String responseCode;

        private String responseMessage;

        /**
         * 构造函数，初始化数据
         */
        public Builder(T data) {
            this.data = data;
        }

        /**
         * 无参构造函数
         */
        public Builder() {
        }

        /**
         * 设置响应数据
         */
        public Builder data(T data) {
            this.data = data;
            return this;
        }

        /**
         * 设置响应代码
         */
        public Builder responseCode(String responseCode) {
            this.responseCode = responseCode;
            return this;
        }

        /**
         * 设置响应消息
         */
        public Builder responseMessage(String responseMessage) {
            this.responseMessage = responseMessage;
            return this;
        }

        /**
         * 构建成功的响应
         */
        public ChainProcessResponse buildSuccess() {
            ChainProcessResponse response = new ChainProcessResponse();
            response.setSuccess(true);
            response.data = this.data;
            return response;
        }

        /**
         * 构建失败的响应
         */
        public ChainProcessResponse buildFailed() {
            ChainProcessResponse response = new ChainProcessResponse();
            response.setSuccess(false);
            response.setResponseCode(this.responseCode);
            response.setResponseMessage(this.responseMessage);
            return response;
        }
    }
}
